home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / KOOB / common / main.cs < prev    next >
Text File  |  2006-07-02  |  4KB  |  153 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //-----------------------------------------------------------------------------
  7. // Load up defaults console values.
  8.  
  9. exec("./defaults.cs");
  10.  
  11. //-----------------------------------------------------------------------------
  12.  
  13. function initCommon()
  14. {
  15.    // All mods need the random seed set
  16.    setRandomSeed();
  17.  
  18.    // Very basic functions used by everyone
  19.    exec("./client/canvas.cs");
  20.    exec("./client/audio.cs");
  21. }
  22.  
  23. function initBaseClient()
  24. {
  25.    // Base client functionality
  26.    exec("./client/message.cs");
  27.    exec("./client/mission.cs");
  28.    exec("./client/missionDownload.cs");
  29.    exec("./client/actionMap.cs");
  30.  
  31.    // There are also a number of support scripts loaded by the canvas
  32.    // when it's first initialized.  Check out client/canvas.cs
  33. }
  34.  
  35. function initBaseServer()
  36. {
  37.    // Base server functionality
  38.    exec("./server/audio.cs");
  39.    exec("./server/server.cs");
  40.    exec("./server/message.cs");
  41.    exec("./server/commands.cs");
  42.    exec("./server/missionInfo.cs");
  43.    exec("./server/missionLoad.cs");
  44.    exec("./server/missionDownload.cs");
  45.    exec("./server/clientConnection.cs");
  46.    exec("./server/kickban.cs");
  47.    exec("./server/game.cs");
  48. }   
  49.  
  50.  
  51. //-----------------------------------------------------------------------------
  52. package Common {
  53.  
  54. function displayHelp() {
  55.    Parent::displayHelp();
  56.    error(
  57.       "Common Mod options:\n"@
  58.       "  -fullscreen            Starts game in full screen mode\n"@
  59.       "  -windowed              Starts game in windowed mode\n"@
  60.       "  -autoVideo             Auto detect video, but prefers OpenGL\n"@
  61.       "  -openGL                Force OpenGL acceleration\n"@
  62.       "  -directX               Force DirectX acceleration\n"@
  63.       "  -voodoo2               Force Voodoo2 acceleration\n"@
  64.       "  -noSound               Starts game without sound\n"@
  65.       "  -prefs <configFile>    Exec the config file\n"
  66.    );
  67. }
  68.  
  69. function parseArgs()
  70. {
  71.    Parent::parseArgs();
  72.  
  73.    // Arguments override defaults...
  74.    for (%i = 1; %i < $Game::argc ; %i++)
  75.    {
  76.       %arg = $Game::argv[%i];
  77.       %nextArg = $Game::argv[%i+1];
  78.       %hasNextArg = $Game::argc - %i > 1;
  79.    
  80.       switch$ (%arg)
  81.       {
  82.          //--------------------
  83.          case "-fullscreen":
  84.             $pref::Video::fullScreen = 1;
  85.             $argUsed[%i]++;
  86.  
  87.          //--------------------
  88.          case "-windowed":
  89.             $pref::Video::fullScreen = 0;
  90.             $argUsed[%i]++;
  91.  
  92.          //--------------------
  93.          case "-noSound":
  94.             error("no support yet");
  95.             $argUsed[%i]++;
  96.  
  97.          //--------------------
  98.          case "-openGL":
  99.             $pref::Video::displayDevice = "OpenGL";
  100.             $argUsed[%i]++;
  101.  
  102.          //--------------------
  103.          case "-directX":
  104.             $pref::Video::displayDevice = "D3D";
  105.             $argUsed[%i]++;
  106.  
  107.          //--------------------
  108.          case "-voodoo2":
  109.             $pref::Video::displayDevice = "Voodoo2";
  110.             $argUsed[%i]++;
  111.  
  112.          //--------------------
  113.          case "-autoVideo":
  114.             $pref::Video::displayDevice = "";
  115.             $argUsed[%i]++;
  116.  
  117.          //--------------------
  118.          case "-prefs":
  119.             $argUsed[%i]++;
  120.             if (%hasNextArg) {
  121.                exec(%nextArg, true, true);
  122.                $argUsed[%i+1]++;
  123.                %i++;
  124.             }
  125.             else
  126.                error("Error: Missing Command Line argument. Usage: -prefs <path/script.cs>");
  127.       }
  128.    }
  129. }
  130.  
  131. function onStart()
  132. {
  133.    Parent::onStart();
  134.    echo("\n--------- Initializing MOD: Common ---------");
  135.    initCommon();
  136. }
  137.  
  138. function onExit()
  139. {
  140.    echo("Exporting client prefs");
  141.    export("$pref::*", "./client/prefs.cs", False);
  142.  
  143.    echo("Exporting server prefs");
  144.    export("$Pref::Server::*", "./server/prefs.cs", False);
  145.    BanList::Export("./server/banlist.cs");
  146.  
  147.    OpenALShutdown();
  148.    Parent::onExit();
  149. }
  150.  
  151. }; // Common package
  152. activatePackage(Common);
  153.